package com.it2297.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;

import com.it2297.controller.JobController;
import com.it2297.main.App;
import com.it2297.main.UserApp;

import javax.swing.JTextArea;

public class JobApplication extends JFrame {

	private JPanel contentPane;
	private JTextField tf_title;
	private JTextField tf_nname;
	private JTextField tf_nric;
	private JTextField tf_email;
	private JTextField textField_4;
	private JTextField txtOptional;
	private JTextField textField;
	private JTextField tf_phone;
	private JTextArea tf_info;
	final JobController jct= new JobController(this);
	
	public void setJobTitle(String jobTitle){

        tf_title.setText(jobTitle);
	}
	
	 public String getTitle(){
         return tf_title.getText();
	 }
	 
	 public String getNRIC(){
		 return tf_nric.getText();
	 }
	
	 public String getName(){
		 
		 return tf_nname.getText();
	 }
	 
	 public String getEmail(){
		 return tf_email.getText();
	 }
	 
	 public String getPhone(){
		 return tf_phone.getText();
	 }
	 public String getInfo(){
		 return tf_info.getText();
	 }

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JobApplication frame = new JobApplication();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
*/
	/**
	 * Create the frame.
	 */
	public JobApplication() {
	//	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 740, 560);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		JLabel lblNewLabel = new JLabel("Job Application");
		lblNewLabel.setBounds(57, 11, 657, 71);
		lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD, 35));
		getContentPane().add(lblNewLabel);
		
		JLabel lbljobtitle = new JLabel("Applying for  ");
		lbljobtitle.setBounds(57, 80, 158, 27);
		lbljobtitle.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(lbljobtitle);
		
		JLabel lblname = new JLabel("Name:");
		lblname.setBounds(57, 118, 158, 27);
		lblname.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(lblname);
		
		JLabel lblnric = new JLabel("NRIC:");
		lblnric.setBounds(57, 156, 158, 27);
		lblnric.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(lblnric);
		
		JLabel lblemail = new JLabel("Email:");
		lblemail.setBounds(57, 194, 158, 27);
		lblemail.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(lblemail);
		
		JLabel lblphone = new JLabel("Phone number:");
		lblphone.setBounds(57, 232, 117, 27);
		lblphone.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(lblphone);
		
	/*	JLabel lblresumeid = new JLabel("Resume ID:");
		lblresumeid.setBounds(57, 328, 158, 27);
		lblresumeid.setFont(new Font("Tahoma", Font.BOLD, 15));
		add(lblresumeid);*/
		
		tf_title = new JTextField();
		tf_title.setEditable(false);
		tf_title.setBounds(181, 84, 378, 22);
		getContentPane().add(tf_title);
		tf_title.setColumns(10);
		
		tf_nname = new JTextField();
		tf_nname.setText(UserApp.getCurrentUser().getName());
		//tf_nname.setText(UserApp.getCurrentNeedy().getName());
		tf_nname.setEditable(false);
		tf_nname.setBounds(181, 122, 327, 22);
		getContentPane().add(tf_nname);
		tf_nname.setColumns(10);
		
		tf_nric = new JTextField();
		tf_nric.setEditable(false);
		tf_nric.setText(UserApp.getCurrentUser().getNric());
		//tf_nric.setText(UserApp.getCurrentNeedy().getNric());
	//	tf_nric.setText("S9834792H");
		tf_nric.setBounds(181, 160, 158, 22);
		getContentPane().add(tf_nric);
		tf_nric.setColumns(10);
		
		tf_email = new JTextField();
		tf_email.setText(UserApp.getCurrentUser().getEmail());
		//tf_email.setText(UserApp.getCurrentNeedy().getEmail());
		tf_email.setEditable(false);
		tf_email.setBounds(181, 194, 287, 22);
		getContentPane().add(tf_email);
		tf_email.setColumns(10);
		
		tf_phone = new JTextField();
		tf_phone.setText(UserApp.getCurrentUser().getPhone());
	//	tf_phone.setText(UserApp.getCurrentNeedy().getPhone());
		tf_phone.setEditable(false);
		tf_phone.setBounds(181, 236, 117, 22);
		contentPane.add(tf_phone);
		tf_phone.setColumns(10);
		
		JButton btnClose = new JButton("Close");
		btnClose.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				closeWindow();
			}
		});
		btnClose.setBounds(247, 445, 89, 27);
		contentPane.add(btnClose);
		
		JButton btnSubmitApplication = new JButton("Submit Application");
		btnSubmitApplication.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(tf_title.getText().equals("") || tf_nname.getText().equals("") ||tf_nric.getText().equals("") || tf_email.getText().equals("") || tf_phone.getText().equals("")||tf_info.getText().equals("")){
           //    if(tf_title.getText().equals("") ||tf_nric.getText().equals("")||tf_info.getText().equals("")){
				JOptionPane.showMessageDialog(null,"Please fill in all the necessary details.");	
				}
				 else{
					 jct.applyForJob();
					 closeWindow();
				 }
			}
		});
		btnSubmitApplication.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnSubmitApplication.setBounds(57, 445, 180, 27);
		contentPane.add(btnSubmitApplication);	
		
		JLabel lblShortParagraphOf = new JLabel("Short paragraph of past experiences / highest education level etc.");
		lblShortParagraphOf.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblShortParagraphOf.setBounds(57, 270, 502, 27);
		contentPane.add(lblShortParagraphOf);
		
		tf_info = new JTextArea();
		tf_info.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
		tf_info.setBounds(57, 295, 636, 139);
		contentPane.add(tf_info);
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(0, 0, 724, 522);
		contentPane.add(panel);
	}
	
	public void closeWindow(){
		this.dispose();
	}
}
